package com.nwpu.bigdata.util.impl;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import com.nwpu.bigdata.util.ESRestUtil;

/**
 * @author zhanggr
 *
 */
@Configuration
@ImportResource(locations = {"classpath:/xmlConfig/spring/applicationContext-util.xml"})
public class ESRestUtilImpl implements ESRestUtil {

	@Value("${es.host}")
	String esHost;

	@Value("${es.port}")
	String esPort;

	@Value("${es.clusterName}")
	String esClusterName;

	@Override
	@Bean("restHighLevelClient")
	public RestHighLevelClient createClient() {
		return new RestHighLevelClient(RestClient.builder(
				new HttpHost(esHost, Integer.valueOf(esPort), "http")));
	}

}
